﻿using System;
using SapaFinance.Domain.Extensions;

namespace SapaFinance.Domain.Model
{
    public class Pair : AbstractEntity
    {
        public Pair(Currency from, Currency to)
        {
            Date = DateTime.Now.Date;
            From = from;
            To = to;
        }

        public DateTime Date{get; private set; }
        public Currency From { get; private set; }
        public Currency To { get; private set; }
        private DecimalSize _size; 
        private decimal _value;
        public decimal Value { get { return _value.RoundTo(_size); } }

        public Pair SetValue(decimal value)
        {
            _size = DecimalSize.Four;
            _value = value;
            return this;
        }

        public Pair Inverse()
        {
            return new Pair(To, From).SetValue((1 / _value)).SetRoundSize(_size);
        }
        public override bool Equals(object obj)
        {
            var compare = (Pair)obj;
            if (ReferenceEquals(null, compare)) return false;
            if (UID != Guid.Empty) return base.Equals(compare);
            return Value == compare.Value && From.Equals(compare.From) && To.Equals(compare.To) && Date.Equals(compare.Date);
        }

        public Pair SetRoundSize(DecimalSize decimalSize)
        {
            _size = decimalSize;
            return this;
        }

    }
}